package com.huipinche.view.impl;

import javax.imageio.ImageIO;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import java.util.Date;

import com.huipinche.view.LaunchPageView;
import com.huipinche.view.utils.*;
import com.huipinche.service.impl.*;
import com.huipinche.dao.bean.*;
public class LaunchPageViewimpl  implements LaunchPageView {
    final int WIDTH = 510;
    final int HEIGHT = 689;
    private int page = 0;
    private boolean flag = true;
    private JPanel contentPane;
    private BackGroundPanel bgPanel;
    private JFrame loginFrame;

    private JTextField textField;
    private JTextField textField_1;
    private JTextField textField_2;
    private JTextField textField_3;
    private JLabel lblNewLabel;
    private  JLabel label;
    private JLabel label01;
    private JLabel label02;
    private JLabel label03;

    /**
     * Launch the application.
     */
    /*public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    LaunchPageViewimpl frame = new LaunchPageViewimpl();
                    frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }*/

    /**
     * Create the frame.
     */
    public void initialize() {
        loginFrame = new JFrame("慧拼车-发布拼单");
        //loginFrame.setTitle();
        loginFrame.setVisible(true);
        loginFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        loginFrame.setBounds((ScreenUtils.getScreenWidth() - WIDTH) / 2,
                (ScreenUtils.getScreenHeight() - HEIGHT) / 2, WIDTH, HEIGHT);
        try {
            loginFrame.setIconImage(ImageIO.read(new File(PathUtils.getRealPath("logo3.jpeg"))));
        } catch (IOException e) {
            e.printStackTrace();
        }
        Image image01=new ImageIcon(PathUtils.getRealPath("bigbackground3.png")).getImage();
        bgPanel = new BackGroundPanel(image01);
        // bgPanel.setBounds(0,0,WIDTH,HEIGHT);


        // contentPane = new JPanel();
        bgPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
        loginFrame.setContentPane(bgPanel);
        bgPanel.setLayout(null);

        textField = new JTextField();
        textField.setText("");
        textField.setBounds(100, 282, 388, 40);
        bgPanel.add(textField);
        textField.setColumns(10);
        textField.setOpaque(false);
        textField.setFont(new Font("楷体",Font.BOLD,18));
        textField.setForeground(Color.black);

        label = new JLabel("时间 :");
        label.setBounds(10, 282, 100, 40);
        label.setFont(new Font("楷体",Font.BOLD,18));
        label.setForeground(Color.black);
        bgPanel.add(label);


        textField_1 = new JTextField();
        textField_1.setText("");
        textField_1.setBounds(100, 348, 388, 40);
        bgPanel.add(textField_1);
        textField_1.setColumns(10);
        textField_1.setOpaque(false);
        textField_1.setFont(new Font("楷体",Font.BOLD,18));
        textField_1.setForeground(Color.black);

        label01 = new JLabel("出发地 :");
        label01.setBounds(10, 348, 100, 40);
        label01.setFont(new Font("楷体",Font.BOLD,18));
        label01.setForeground(Color.black);
        bgPanel.add(label01);

        textField_2 = new JTextField();
        textField_2.setText("");
        textField_2.setBounds(100, 411, 388, 40);
        bgPanel.add(textField_2);
        textField_2.setColumns(10);
        textField_2.setOpaque(false);
        textField_2.setFont(new Font("楷体",Font.BOLD,18));
        textField_2.setForeground(Color.black);

        label02 = new JLabel("目的地：");
        label02.setBounds(10, 411, 100, 40);
        label02.setFont(new Font("楷体",Font.BOLD,18));
        label02.setForeground(Color.black);
        bgPanel.add(label02);


        textField_3 = new JTextField();
        textField_3.setText("");
        textField_3.setBounds(100, 477, 388, 40);
        bgPanel.add(textField_3);
        textField_3.setColumns(10);
        textField_3.setOpaque(false);
        textField_3.setFont(new Font("楷体",Font.BOLD,18));
        textField_3.setForeground(Color.black);

        label03 = new JLabel("电话号码：");
        label03.setBounds(10, 477, 100, 40);
        label03.setFont(new Font("楷体",Font.BOLD,18));
        label03.setForeground(Color.black);
        bgPanel.add(label03);

        //设置图标
        Icon confirm = new ImageIcon((PathUtils.getRealPath("car3.png")));
        Icon abandon = new ImageIcon((PathUtils.getRealPath("car2.png")));
        Icon back = new ImageIcon((PathUtils.getRealPath("car3.png")));


        JButton btnNewButton = new JButton("确认发布");
        btnNewButton.setForeground(Color.black);
        btnNewButton.setIcon(confirm);
        btnNewButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                new GeneralPageimpl("发布成功");
           //     System.out.println(99999);
           //     System.out.println(textField.getText());

                Date d1 = new Date(2021, 11, 30);
                Journey journey = new launchJourneyServiceimpl().launchJourney(d1,
                        textField_1.getText(),textField_2.getText(),textField_3.getText());
//                Journey journey = new launchJourneyServiceimpl().launchJourney(new Date(textField.getText()),
//                        textField_1.getText(),textField_2.getText(),textField_3.getText());
            //    System.out.println(66666);

//                System.out.println(journey);//能够完全打印数组吗？
                // new GeneralPageimpl("发布成功");

            }
        });
        btnNewButton.setBounds(25, 577, 140, 30);
        bgPanel.add(btnNewButton);

        JButton btnNewButton_1 = new JButton("放弃发布");
        btnNewButton_1.setIcon(abandon);
        btnNewButton_1.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                new GeneralPageimpl("放弃发布成功");//放弃发布成功
                textField.setText("");
                textField_1.setText("");
                textField_2.setText("");
                textField_3.setText("");
            }
        });
        ImageIcon image=new ImageIcon("01.JPG");
        btnNewButton_1.setBounds(189, 577, 140, 30);
        bgPanel.add(btnNewButton_1);

        JButton btnNewButton_2 = new JButton("返回主页");
        btnNewButton_2.setIcon(back);
        LaunchPageViewimpl temp = this;
        btnNewButton_2.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                temp.page = 200;
                temp.flag = false;
            }
        });
        btnNewButton_2.setBounds(338, 577, 140, 30);
        bgPanel.add(btnNewButton_2);

        JComboBox comboBox = new JComboBox();
        comboBox.addItem("定位");    //向下拉列表中添加一项
        comboBox.addItem("1");
        comboBox.addItem("2");
        comboBox.addItem("3");
        comboBox.setBounds(10, 10, 55, 34);
        bgPanel.add(comboBox);
        //  bgPanel.add(bgPanel);

        lblNewLabel = new JLabel(new ImageIcon("C:\\Users\\qing'feng\\IdeaProjects\\registration\\images\\01.JPG"));//图片路径
        lblNewLabel.setBounds(10, 54, 457, 213);
        bgPanel.add(lblNewLabel);

       // loginFrame.add(bgPanel);

       // loginFrame.setVisible(true);
        loginFrame.setResizable(false);

    }

    @Override
    public int LaunchPage(boolean flag) throws InterruptedException {
        this.flag = flag;
            initialize();
        while(this.flag){
            Thread.sleep(200);
        };
        switch (page){
                case 200:
                loginFrame.removeNotify();
                return 200;
            }
        return 0;
    }
}
